package com.zhxy.util.osgi;

import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.frameworks;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.CoreOptions.when;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.ExamReactorStrategy;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactorFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;

@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(EagerSingleStagedReactorFactory.class)
public class MyTestCase {

	@Configuration
	public Option[] config() {
		System.out.println("!!!!!!!!!!!MyTestCase");
		Option debugOption = when(true)
				.useOptions(
						vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"));
		return options(
				frameworks(equinox().version("3.7.0")),
				debugOption,
				systemProperty("maven.home").value(
						"D:\\bin\\apache-maven-3.0.1"));
	}

	@Test
	public void test1(BundleContext context) {
		
		System.out.println("!!!!!!!!" + System.getenv("PATH") + "!!!!!!!!");
		System.out.println("!!!!!!!!" + context + "!!!!!!!!");

		System.out.println(context.getDataFile("a.tmp"));
		for (Bundle bundle : context.getBundles()) {
			System.out.println(bundle.getDataFile("a.tmp"));
		}

		context.addBundleListener(new BundleListener() {

			@Override
			public void bundleChanged(BundleEvent event) {

			}
		});

		context.addServiceListener(new ServiceListener() {

			@Override
			public void serviceChanged(ServiceEvent event) {

			}
		});

		System.out.println("hello world");

	}
}
